//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
// 
// You should have received a copy of the GNU Lesser General Public License
// along with this program.  If not, see http://www.gnu.org/licenses/.
// 

#ifndef EMULATE3G_H_
#define EMULATE3G_H_

#include "INETDefs.h"
#include "BasicBattery.h"
#include "RadioState.h"

typedef enum {
    OFF_3G,
    IDLE_3G,
    BUSY_3G
} States_3G;

#define FINAL_STAT_MEAN_PERIOD  20

class INET_API Emulate3G : public cSimpleModule
{
//    friend class StemNetStimulusBrain;

public:
    Emulate3G();
    virtual ~Emulate3G();

    // return queue information
    double getQueueSize(void);
    double getMaxQueueSize(void);

    void switchON(void);
    void switchOFF(void);

    // STATS
    double getAveragePktSentPerSeconds(simtime_t time);

protected:
  virtual int numInitStages() const {return 2;}
  virtual void initialize(int stage);
  virtual void handleMessage(cMessage *msg);
  virtual void finish();

  virtual void handleSelfMsg(cMessage *msg);
  virtual void handleBrainMsg(cMessage *msg);
  virtual void registerBattery(void);

  //stats
  void makePeriodocStats(void);
  void makeFinalStats(void);

protected:
  /** @name gate from brain */
  /*@{*/
  int brainIn;
  /*@}*/

  /** @name gate to brain */
  /*@{*/
  int brainOut;
  /*@}*/

private:

    NotificationBoard *nb; // Cached pointer to the NotificationBoard module

    int maxQueueSize;
    double cellularCapacity;

    double usage_3g_radio;
    DrawAmount energyToDraw;

    std::list<cPacket *> pkyQueue;

    BasicBattery *batt;
    //int myBatteryID;

    cMessage *msgEndPkt;

    States_3G myState;
    RadioState rs;

    //stats
    int droppedPkt;

    std::list<std::pair<simtime_t, int> > pktSentList;

    cMessage *msgStat;

    cOutVector *byteSent;
    cOutVector *pktSent;
    int countPktSent;
    int totalPktSent;

};

#endif /* EMULATE3G_H_ */
